﻿#include "widget.h"
#include <QTimer>

#include <QDateTime>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    m_host = new QRemoteObjectHost(this);
    m_host->setHostUrl(QUrl("local:myrpc"));
    m_rpc = new MyRPCSimpleSource(this);

    m_host->enableRemoting(m_rpc);

    connect(m_rpc,&MyRPCSource::msgFromA,this,&Widget::onMessageA);
    connect(m_rpc,&MyRPCSource::msgFromB,this,&Widget::onMessageB);
    connect(m_host,&QRemoteObjectHost::error,[](){
        qDebug() << "server host error";
    });

    startTimer(1000);
}

void Widget::timerEvent(QTimerEvent *ev)
{
    qDebug() << "timeout";
    m_rpc->msgFromServer("hello i'm server");
    m_rpc->setText(QDateTime::currentDateTime().toString());
}

Widget::~Widget()
{
}

void Widget::onMessageA(const QString &msg)
{

}

void Widget::onMessageB(const QString &msg)
{

}
